import React, { Component } from "react";
import { Form, Select, Input } from "antd";
// import PropTypes from 'prop-types'
const Item = Form.Item;
const Option = Select.Option;
class AddForm extends Component {
  // static propTypes = {
  //   categorys: PropTypes.array.isReguired,
  //   parentId:PropTypes.string.isRequired
  // }
  // constructor(props) {
  //   super(props);
  //   this.state = {
  //     categorys: props.categorys,
  //   };
  // }
  formRef = React.createRef();
  onFinish = (value) => {
    console.log(value);
  };
  componentDidMount() {
    
  }
  onNoteChange = value => { 
    const formList = this.formRef.current.getFieldsValue()
    this.props.setForm(formList)
  }
  render () {

    return (
      <div>
        <Form ref={ this.formRef } onChange={ this.onNoteChange} onFinish={ this.onFinish}>
          <Item key='0' name="parentId">
            <Select>
              <Option value="0">一级分类</Option>
              {this.props.categorys.map((c) => (
                <Option key={ c._id} value={c._id}>{c.name}</Option>
              ))}
            </Select>
          </Item>
          <Item key='1' name="name">
            <Input placeholder="请输入分类名称" />
          </Item>
        </Form>
      </div>
    );
  }
}

export default AddForm;
